//
//  AppDelegateInit.swift
//  zhende
//
//  Created by 陆文宇 on 2017/5/26.
//  Copyright © 2017年 chenliang. All rights reserved.
//

import UIKit

extension AppDelegate {
    
    func configInit() {
        System.initCities()
        initGoodsCategory()
        initGoodsAttribute()
        initGoodsAttributeRelation()
        initDicItem()
        
        UserDefaults.standard.set(UIApplication.yy_appVersion, forKey: "AppVersion")
        UserDefaults.standard.set(YYRealm.realmVersion, forKey: "RealmVersion")
    }
    
    // MARK: - Init
    
    func initGoodsCategory() {
        yy_post(url: apiUrlPrex + "/s/goodscategory/list", success: { (data) in
            GoodsCategory.create(data as! [[String: Any]])
        }) { (errmsg) -> String? in
            return errmsg
        }
    }
    
    func initGoodsAttribute() {
        yy_post(url: apiUrlPrex + "/s/attribute/list_all", success: { (data) in
            GoodsAttribute.create(data as! [[String: Any]])
        }) { (errmsg) -> String? in
            return errmsg
        }
    }
    
    func initGoodsAttributeRelation() {
        yy_post(url: apiUrlPrex + "/s/attribute/relation_list_all", success: { (data) in
            GoodsAttributeRelation.create(data as! [[String: Any]])
        }) { (errmsg) -> String? in
            return errmsg
        }
    }
    
    func initDicItem() {
        yy_post(url: apiUrlPrex + "/s/dic/item_list_all", success: { (data) in
            GoodsDicItem.create(data as! [[String: Any]])
        }) { (errmsg) -> String? in
            return errmsg
        }
    }
}
